/**
 * 
 */
package kr.co.insoft.auth.mapper.members;

import kr.co.insoft.auth.model.members.JoinFormModel;
import kr.co.insoft.auth.service.initalize.InitializeTableService;
import kr.co.insoft.framework.mybatis.Mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Mapper
public interface JoinMapper {
	@Select("SELECT COUNT(*) FROM `" + InitializeTableService.USERS_TABLE
			+ "` WHERE `username`=#{username}")
	public Integer isDuplicateUsername(String username) throws Exception;

	@Insert("INSERT INTO `"+InitializeTableService.USERS_TABLE+"`(`username`,`nickname`, `password`) VALUES(#{username}, #{nickname}, #{password})")
	@SelectKey(before = false, keyColumn = "id", keyProperty = "id", resultType = java.lang.Long.class, statement = { "SELECT LAST_INSERT_ID()" })
	public Long registMember(JoinFormModel joinFormModel) throws Exception;

	/**
	 * @param id
	 * @return
	 */
	@Select("SELECT * FROM `" + InitializeTableService.USERS_TABLE
			+ "` WHERE `id`=#{id}")
	public JoinFormModel getUser(Long id);

	/**
	 * @param id
	 * 
	 */
	@Update("UPDATE `"
			+ InitializeTableService.USERS_TABLE
			+ "` SET `accountNonExpired`=b'1', `accountNonLocked`=b'1', `credentialsNonExpired`=b'1', `enabled`=b'1'  WHERE `id`=#{id}")
	public void accountRevitalize(Long id);
}
